import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hack_a_tone/utils.dart';

class JiraCubit extends Cubit<(String, String, String, Map<String, String>)> {
  JiraCubit() : super(('', '', '', {}));
  Future<void> login(email, token, domain) async {
    final r = await getProjects(email, token, domain);
    print(r);

    Map<String, String> tasks = {};
    for (var pj in r.entries) {
      final project = pj.key;
      for (var ts in pj.value) {
        final key = ts["task_key"]!;
        final name = ts["task_name"]!;
        tasks[key] = "$project $name";
      }
    }
    emit((email, token, domain, tasks));

  }
  Future<void> timeLeft(Duration dur, String taskId) async {
    String s = formatDuration(dur);
    await addTime(state.$1, state.$2, state.$3, taskId, s); 
  }
}